package com.nidu.demo.common.enums;

import cn.hutool.core.util.ArrayUtil;
import com.nidu.demo.common.validation.IntArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 登录类型枚举
 */
@Getter
@AllArgsConstructor
public enum LoginTypeEnum implements IntArrayValuable {

    /**
     * 登录类型枚举
     */
    LOGIN_USERNAME(100, "使用账号登录"),
    LOGIN_SOCIAL(101, "使用社交登录"),
    LOGIN_MOBILE(103, "使用手机登陆"),
    LOGIN_SMS(104, "使用短信登陆"),

    LOGOUT_SELF(200, "自己主动登出"),
    LOGOUT_DELETE(202, "强制退出"),
    ;

    private final Integer type;
    private final String desc;

    public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(LoginTypeEnum::getType).toArray();

    @Override
    public int[] array() {
        return ARRAYS;
    }

    public static LoginTypeEnum of(Integer val) {
        return ArrayUtil.firstMatch(o -> o.getType().equals(val), values());
    }
}
